<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui" xmlns:t="http://myfaces.apache.org/tomahawk"
	template="/pages/template/main-layout.xhtml">

	<ui:define name="content">
			<t:saveState value="#{therapyBean.therapy}" />
			<t:saveState value="#{therapyBean.therapyParent}" />
			<t:saveState value="#{therapyBean.selectedNode}" />

			<h:panelGrid>
				<p:contextMenu for="therapyTree">
					<p:menuitem value="#{msgs.button_edit}" update="therapyInfo" actionListener="#{therapyBean.edit}"
						icon="ui-icon-pencil" />

					<p:menuitem value="#{msgs.button_add}" update="therapyInfo" actionListener="#{therapyBean.add}"
						icon="ui-icon-plus" />

					<p:menuitem value="add child" update="therapyInfo" actionListener="#{therapyBean.addChild}"
						icon="ui-icon-plus" />

					<p:menuitem value="#{msgs.button_delete}" onclick="confirmDeleteTherapy.show();"
						icon="ui-icon-close" />
				</p:contextMenu>

			</h:panelGrid>

			<h:panelGrid columns="2" cellspacing="5" columnClasses="width30, width70" style="width:100%">
				<h:panelGrid border="0" id="therapyTree">
					<p:tree value="#{therapyBean.rootNode}" var="node" selection="#{therapyBean.selectedNode}"
						selectionMode="single" dynamic="true" cache="false" style="width:100%;">

						<p:treeNode>
							<h:outputText styleClass="ui-icon ui-icon-cancel" rendered="#{node.status eq 0}"/>
							<h:outputText value="#{node.name}" />
							<h:outputText value="&#160;" />
							<h:outputText value="#{node.sort}" />
						</p:treeNode>
					</p:tree>
				</h:panelGrid>

				<h:panelGroup id="therapyInfo">
					<h:inputHidden value="#{therapyBean.therapy.id}" />
					<h:inputHidden value="#{therapyBean.therapyParent.id}" />

					<p:panelGrid columns="2" cellpadding="3" cellspacing="3" style="width:100%"
						columnClasses="width20,width80">
						<f:facet name="header">
							<h:outputText value="#{msgs.therapy_category}" />
						</f:facet>
						
						<h:outputLabel value="#{msgs.qtnaire_parent}" />
						<h:outputText value="#{therapyBean.therapyParent.name}" />
						
						<h:outputLabel value="#{msgs.default_name}" />
						<p:inputText value="#{therapyBean.therapy.name}" maxlength="80"
							style="validator:checkNotNull(#{msgs.default_name});width:90%;" />

						<h:outputLabel value="#{msgs.default_sort}" />
						<p:keyboard value="#{therapyBean.therapy.sort}" keypadOnly="true"/>  

						<f:facet name="footer">
							<p:commandButton value="#{msgs.button_stop}" actionListener="#{therapyBean.stop}"
								icon="ui-icon-locked" update=":messages,therapyInfo,therapyTree"
								rendered="#{therapyBean.therapy.status == 1}" />
							
							<h:outputText value="&#160;" />
							
							<p:commandButton value="#{msgs.button_active}" actionListener="#{therapyBean.active}"
								icon="ui-icon-unlocked" update=":messages, therapyInfo, therapyTree"
								rendered="#{therapyBean.therapy.status == 0}" />
							
							<h:outputText value="&#160;" />
							
							<p:commandButton value="#{msgs.button_submit}" icon="ui-icon-disk" process="therapyInfo"
								onclick="return validator('therapyInfo');" actionListener="#{therapyBean.submit}" type="submit"
								update="therapyTree,:messages" />
						</f:facet>
					</p:panelGrid>
				</h:panelGroup>
			</h:panelGrid>
	</ui:define>
	<ui:define name="dialog">
		<h:panelGrid>
			<p:confirmDialog message="#{msgs.info_sure_delete}" width="200" showEffect="explode"
				hideEffect="explode" header="POZOR" severity="alert" widgetVar="confirmDeleteTherapy" modal="true">
				<p:commandButton value="DA" update=":mainform:therapyInfo,:mainform:therapyTree,:messages"
					actionListener="#{therapyBean.delete}" oncomplete="confirmDeleteTherapy.hide()" />
				<p:commandButton value="NE" onclick="confirmDeleteTherapy.hide()" type="button" />
			</p:confirmDialog>
		</h:panelGrid>
	</ui:define>
</ui:composition>

